<template>
  <div>
    <el-container style="margin-bottom: 10px">为学生设置选课时间： </el-container>
    <div class="block">
      <el-date-picker v-model="value" type="datetimerange" align="right" start-placeholder="开始时间" end-placeholder="结束时间" :default-time="['12:00:00', '08:00:00']"> </el-date-picker>
      <el-button plain style="margin-left: 10px" @click="summit" :disabled="buttonDisable">确定</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AdminStudent',
  data() {
    return {
      value: '',
      buttonDisable: false
    }
  },
  methods: {
    async summit() {
      this.buttonDisable = true
      const { data: res } = await this.$http.post('/setSelectTime', { type: 'student', startTime: this.value[0], endTime: this.value[1] })
      if (res) this.$message('时间修改成功！')
      else this.$alert('修改失败！')
      this.buttonDisable = false
    }
  },
  async created() {
    const { data: res } = await this.$http.post('/getSelectTime', { type: 'student' })
    this.value = [new Date(res.startTime), new Date(res.endTime)]
  }
}
</script>

<style lang="less" scoped></style>
